Describe new API related to triggers#46
Conversation
- new API reference page for the hide-suggest event - documents when the dropdown closes (selection, Escape, cursor leaves trigger, empty result)
- new API reference page for the insert-token event - documents callback fields (id, label, url, trigger, showTrigger)
- new API reference page for the show-suggest event - documents callback fields (trigger, query, items, pos) and intercept example
- new API reference page for the triggers property - covers static array, sync function, async function data sources - documents suggestion item fields and rendered token CSS targeting
- new API reference page for the triggerTemplate property - documents callback parameters (data, trigger) and template usage - includes tip on overriding the dropdown anchor width
- new guide covering trigger characters, data source forms, token rendering, and event handling - examples for static array, sync function, async function, and custom dropdown templates
- list hide-suggest, insert-token, and show-suggest in the events table
- list triggers and triggerTemplate in the properties table
- list triggers in the property overview with a link to the Mentions and tags guide
- update anchor in whats_new from #custom-toolbar-controls to #add-custom-toolbar-controls to match the heading in configuration.md
- add hide-suggest, insert-token, show-suggest under events - add triggers and trigger-template under properties - add mentions_and_tags under guides
kullias
left a comment
There was a problem hiding this comment.
the code changes somewhat in a side branch on custom actions, I added comments, for source code DM either me or the author of the code, we'll point to the branch
- add `action` field to triggers config with Custom action section (emoji insertion and slash-style command menu examples) - update insert-token event payload: id/label/url replaced by `data` object carrying the picked item plus custom fields; add `action` - note that `action` takes priority over `showTrigger` - show-suggest items now documented as optional fields + custom keys - extend mentions guide with custom action examples - fix typos, a broken anchor, and align wording across pages
- destructure ({ data, trigger, showTrigger }) to match the
insert-token event docs and the PR review suggestion
|
|
||
| - `id` - (optional) unique identifier saved on the inserted token. If omitted, RichText generates an ID automatically | ||
| - `label` - (required) the text shown in the dropdown and inserted into the document | ||
| - `url` - (optional) URL associated with the item. RichText stores the inserted token URL as the `href` attribute. |
There was a problem hiding this comment.
ctrl-click to open this link
There was a problem hiding this comment.
Done. The url field now notes that Ctrl+Click on the token opens the link.
| When a user selects an item in the dropdown, RichText inserts a non-editable token element into the document: | ||
|
|
||
| ~~~html {} | ||
| <a data-token="@" data-token-id="alice" href="mailto:alice@example.com">@Alice</a> |
There was a problem hiding this comment.
Where:
@istriggeraliceisidmailto:alice@example.comisurl@Alice- combination oftriggerandlabel, in case ofshowTrigger: falseit would be justAlice
There was a problem hiding this comment.
Done. Added a Where: breakdown under the token: @ → trigger (data-token), alice → id (data-token-id), mailto:alice@example.com → url (href), and @Alice → trigger + label (just Alice when showTrigger: false).
|
|
||
| #### Add emoji | ||
|
|
||
| A common use case is inserting an emoji from a `:` trigger, where each item contains a custom `code` field. Pair `action` with [`triggerTemplate`](api/config/trigger-template.md) so the dropdown shows the emoji itself instead of just its label: |
There was a problem hiding this comment.
maybe it's better to use this snippet code with categories (it is also a good example of custom data filtering): https://snippet.dhtmlx.com/r16rmt4m
There was a problem hiding this comment.
Done. Thanks for the snippet — added a new "Group emoji by category" section based on it: category headers (items with no code), custom data filtering that keeps only categories with matches, a triggerTemplate that renders headers in bold, and an api.intercept("insert-token", ...) guard so headers cannot be inserted. Kept the simpler "Add emoji" example above it as an intro.
| new richtext.Richtext("#root", { | ||
| triggers: [{ trigger: "@", data: people }], | ||
| triggerTemplate: template(obj => { | ||
| if (obj.trigger === "@") { |
There was a problem hiding this comment.
maybe add one more trigger, because otherwise there is no point in checking for equality to a "@"
There was a problem hiding this comment.
Done. Added a second # trigger so the obj.trigger === "@" branch is actually meaningful, with the # dropdown falling back to the plain label.
| - `trigger` - the trigger character that opened the dropdown (`"@"`, `"#"`, etc.) | ||
|
|
||
| :::tip | ||
| The dropdown anchor has a fixed default width of `160px`. To make room for a wider template, override the width from a parent stylesheet (`!important` is needed because the widget sets the default via its own scoped CSS): |
There was a problem hiding this comment.
u can just make bit more complex css rule, like .wx-editor .wx-suggest-anchor instead of !important
There was a problem hiding this comment.
Done. Replaced !important with the more specific .wx-editor .wx-suggest-anchor selector and updated the tip text to explain why the extra parent makes the rule win.
| Each item in the `data` object (or each item returned by a function) has the following fields: | ||
|
|
||
| - `id` - (optional) unique identifier saved on the inserted token. If omitted, RichText generates an ID automatically | ||
| - `label` - (required) the text shown in the dropdown and inserted into the document |
There was a problem hiding this comment.
not really required, u can use custom template (for example: triggerTemplate: template(({data}) => data.id))
There was a problem hiding this comment.
Done. label is now marked (optional), with a note that it is required only for the default rendering — with a custom triggerTemplate you can render from other fields (e.g. template(({ data }) => data.id)) and omit it.
|
|
||
| ### Custom action | ||
|
|
||
| By default, when a user picks an item, RichText inserts it into the document as a token. Set the `action` parameter to run your own code instead: RichText removes the typed trigger string (the trigger character and the query) and calls the `action(item)` callback with the picked item. No token is inserted, so you can decide what to add to the document. The `action` parameter takes priority over `showTrigger`. When `action` is set, `showTrigger` is ignored. |
There was a problem hiding this comment.
so you can decide what to add to the document or don't add anything at all, but call your custom code
There was a problem hiding this comment.
Done. Reworded: "No token is inserted, so you can decide what to add to the document (or run your custom code)."
| { | ||
| trigger: "@", | ||
| data: [ | ||
| { id: "alice", label: "Alice", url: "mailto:alice@example.com" }, |
There was a problem hiding this comment.
url: "mailto:alice@example.com"
so ctrl-click automatically launches your default email client (like Gmail, Outlook, or Apple Mail) and prefills a new email draft with the recipient's address
There was a problem hiding this comment.
Done. Added a note under the example: because the @ items use a mailto: value, Ctrl+Click on the token launches the default email client (Gmail, Outlook, Apple Mail, …) and opens a new message pre-filled with the recipient address.
| ### Suggestion item fields | ||
|
|
||
| Each item in `data` (or each item returned by a function) has the following fields: | ||
| Each item in the `data` object (or each item returned by a function) has the following fields: |
There was a problem hiding this comment.
data is not an object, it's an array or a function that returns an array (so the previous description was correct and all that's above too. returning the old wording is enough, no need to repeat again that it's an array or a function)
| return String.fromCodePoint(parseInt(code, 16)); | ||
| } | ||
|
|
||
| const emoji = [ |
There was a problem hiding this comment.
should be declared before it's read in line 158. if a user copies this code and pastes, this will throw. if I understand correctly, you moved it to make the snippet better readable - understandable, but alas. shorten the emoji array, that would make the snippet neater, and move it before line 154.
- mark suggestion `label` as optional (custom triggerTemplate case) - note Ctrl+Click opens token url, explain mailto behavior - break down rendered token attributes (trigger/id/url/label) - clarify custom action can run code without inserting content - add "Group emoji by category" example with custom filtering, category headers and api.intercept guard - triggerTemplate: add second trigger so trigger check is meaningful, replace !important width tip with more specific selector
No description provided.